<?php

namespace app\admin\controller;

class Goods extends AdminBase
{
    public function index()
    {
        return view();
    }

    public function add()
    {
        return view();
    }

    public function save()
    {
        if (!$this->request->isPost()) {
            return show(config("status.error"), "请求方法不合法");
        }
        $param = input("param.");
//        dump($param);
        $validate = new \app\admin\validate\Goods();
//        dump($validate->check($param));
        if (!$validate->check($param)) {
            return show(config("status.error"), $validate->getError());
        }
        // 数据处理
        $param['category_path_id'] = $param['category_id'];
        $res = explode(",", $param['category_id']);
        $param['category_id'] = end($res);

        $result = (new \app\common\business\Goods())->insertData($param);

        if ($result) {
            return show(config("status.success"), "新增成功");
        } else {
            return show(config("status.error"), "新增失败");
        }

    }
}